package com.mall.common.exception;

import com.mall.common.enums.ResponseEnum;
import com.mall.common.service.IResponseInterface;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * @author wuyijie
 * @className: BizException
 * @description: TODO 公共异常类
 * @date 2021/6/12 00:48
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BizException extends RuntimeException implements Serializable {

    private static final long serialVersionUID = 1L;

    private int errorCode;
    private String errorMessage;

    public BizException() {
        super();
    }

    public BizException(int errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public BizException(ResponseEnum responseEnum) {
        super(String.valueOf(responseEnum.getResponseCode()));
        this.errorCode = responseEnum.getResponseCode();
        this.errorMessage = responseEnum.getResponseMessage();
    }

    public BizException(IResponseInterface iResponseInterface) {
        super(String.valueOf(iResponseInterface.getResponseCode()));
        this.errorCode = iResponseInterface.getResponseCode();
        this.errorMessage = iResponseInterface.getResponseMessage();
    }

    public BizException(IResponseInterface iResponseInterface, Throwable cause) {
        super(String.valueOf(iResponseInterface.getResponseCode()),cause);
        this.errorCode = iResponseInterface.getResponseCode();
        this.errorMessage = cause.getMessage();
    }

    public BizException(String message, int errorCode, String errorMessage) {
        super(message);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public BizException(String message, Throwable cause, int errorCode, String errorMessage) {
        super(message, cause);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public BizException(Throwable cause, int errorCode, String errorMessage) {
        super(cause);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public BizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, int errorCode, String errorMessage) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }
}
